<?php
header ("Content-Type:text/html; charset= utf-8");

require_once ('config.php');
require_once (WEBSITEURL.'/'.ADMINLOC.'/message_admin.php');
require_once (WEBSITEURL.'/'.ADMINLOC.'/message_function.php');


if (!empty($_POST)) {
    // save logic 
    if(get_magic_quotes_gpc()){
	$nickname = htmlspecialchars(trim($_POST['nickname']));
	$email = htmlspecialchars(trim($_POST['email']));
	$content = htmlspecialchars(trim($_POST['content']));
} else {
	$nickname = addslashes(htmlspecialchars(trim($_POST['nickname'])));
	$email = addslashes(htmlspecialchars(trim($_POST['email'])));
	$content = addslashes(htmlspecialchars(trim($_POST['content'])));
}
if(strlen($nickname)>16){
	exit('错误：昵称不得超过16个字符串 [ <a href="javascript:history.back()">返 回</a> ]');
}
if(strlen($nickname)>60){
	exit('错误：邮箱不得超过60个字符串 [ <a href="javascript:history.back()">返 回</a> ]');
}
$createtime = time();
$ip = get_client_ip();
$insert_sql = "INSERT INTO guest_book (nickname,email,content,createtime,clientip) VALUES";
$insert_sql .= "('$nickname','$email','$content',$createtime,'$ip')";


if(mysql_query($insert_sql)){
  
}else {
	echo '留言失败：',mysql_error(),'[ <a href="javascript:history.back()">返 回</a> ]';
}
  
}


$page = isset($_GET['page']) ? $_GET['page'] : 1 ;
$offset=0;
if(isset($_GET['offset'])){
	$offset=$_GET['offset'];
}
$system=new System();

$sys_style=$system->getSysStyle();
$smarty->template_dir=WEBSITEURL."/templates/$sys_style/message";
$smarty->assign("template_dir","templates/$sys_style");
$smarty->assign("page",$page);
$smarty->assign("offset",$offset);
$smarty->registerPlugin("block","messagepagelist","messagepagelist"); //注册block
$smarty->display("default.htm");